package icn.itcast.listener;

import cn.itcast.dto.OptLogDto;
import cn.itcast.event.SysLogEvent;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Description TODO
 * @Author 张开源
 * @Date 2022/4/9 23:14
 * @Version 1.0
 **/
@Component
@Lazy(false)
public class SysLogListener  {

    @Async
    @EventListener(SysLogEvent.class)
    public void saveLog(SysLogEvent event){
        System.out.println("监听事件");
        OptLogDto eventSource = (OptLogDto) event.getSource();
        long id = Thread.currentThread().getId();
        System.out.println("监听事件："+eventSource+",当前线程id:"+id);
    }
}
